package com.qingke.project_management.command_impl;


import org.apache.ibatis.session.SqlSession;

import com.qingke.project_management.App;
import com.qingke.project_management.Console;
import com.qingke.project_management.IDao.UserMapper;
import com.qingke.project_management.command.Command;
import com.qingke.project_management.pojo.User;

public class LoginCommand extends Command {

	public void execute() {
		
		if(App.getInstance().getUser() != null){
			Console.println("您已经登录，请勿重复登录");
			return;
		}
		
		SqlSession session = super.getSession();
		String username = null;
		String password = null;
		User user = new User();
		UserMapper userMapper = session.getMapper(UserMapper.class);

		while(true){
//			username = Console.askInput("用户名:");
//			password = Console.askInput("密码");
			Console.askInput("请输入注册时的手机号");
			Console.println("【验证码已发送到手机,请注意查收】");
			Console.print("手机验证码>");
			try {
				Thread.sleep(2000);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			Console.println("Bazinga!骗你的，已自动填写用户名密码");
			username = "louzong";
			password = "louzong123";
			user.setUsername(username);
			user.setPassword(password);
			User loginUser = userMapper.login(user);
			
			if(loginUser!=null){
				App.getInstance().setUser(loginUser);
				Console.println("登录成功");
				break;
			}else {
				Console.println("用户名或密码错误，请重新输入");
			}
		}
		
	}

}
